package kr.saeildamil.androidstudy_second.ani;

import kr.saeildamil.andrordstudy.second.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Toast;

public class TweenListener extends Activity {
	Button mBtn;
	Animation mAni1;
	Animation mAni2;
	Animation mAni3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_tweenlistener);
		
		mBtn = (Button)findViewById(R.id.tweenlistener_btn);
		mBtn.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				mBtn.startAnimation(mAni1);
			}
		});
		
		mAni1 = AnimationUtils.loadAnimation(this, R.anim.rotate2);
		mAni2 = AnimationUtils.loadAnimation(this, R.anim.alpha2);
		mAni3 = AnimationUtils.loadAnimation(this, R.anim.scale2);
		
		mAni1.setAnimationListener(listener);
		mAni2.setAnimationListener(listener);
		mAni3.setAnimationListener(listener);
		
/*		mAni1.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				mBtn.startAnimation(mAni2);
			}
		});
		
		mAni2.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				mBtn.startAnimation(mAni3);
			}
		});
		
		mAni3.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			public void onAnimationEnd(Animation animation) {
				String str = animation.toString();
				Toast.makeText(TweenListener.this, "Animation End" + str, Toast.LENGTH_SHORT).show();
			}
		});*/
	}
	
	AnimationListener listener =  new AnimationListener() {
		public void onAnimationStart(Animation animation) {}		
		public void onAnimationRepeat(Animation animation) {}
		public void onAnimationEnd(Animation animation) {
			if (animation.equals(mAni1)){
				mBtn.startAnimation(mAni2);
			}else if (animation.equals(mAni2)){
				mBtn.startAnimation(mAni3);
			}else if (animation.equals(mAni3)){
				Toast.makeText(TweenListener.this, "Animation End", Toast.LENGTH_SHORT).show();
			}
		}
	};
	
}
